package com.navinfo.opentsp.platform.computing.service;

import com.google.common.collect.Lists;
import com.navinfo.opentsp.platform.location.protocol.common.*;
import com.navinfo.platform.bigdata.dto.*;
import org.apache.flume.Event;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public interface IProtocolParseService {
    String splitStr = "\001";
    String nullStr = "\\N";

    String parseProtocol(Event event);

    default List<String> getTemAlarmDtos(List<LCLocationData.TemAddition> temAlarmList){
        List<String> temAlarmDtos = Lists.newArrayList();
        if(temAlarmList == null){
            return temAlarmDtos;
        }
        for(LCLocationData.TemAddition temAddition : temAlarmList){
            temAlarmDtos.add(TemAlarmDto.parseString(temAddition));
        }
        return temAlarmDtos;
    }

    default List<String> getKeyPointFences(List<LCLocationData.KeyPointFenceAddition> keyPointFenceAdditionList){
        List<String> defenceAdditionDtos = Lists.newArrayList();
        if(keyPointFenceAdditionList == null){
            return defenceAdditionDtos;
        }
        for(LCLocationData.KeyPointFenceAddition keyPointFenceAddition : keyPointFenceAdditionList){
            defenceAdditionDtos.add(DefenceAdditionDto.parseString(keyPointFenceAddition));
        }
        return defenceAdditionDtos;
    }

    default List<String> getParkingAdditions(List<LCLocationData.OvertimeParkingAddition> overtimeParkingAdditions){
        List<String> parkingAdditionDtos = Lists.newArrayList();
        if(overtimeParkingAdditions == null){
            return parkingAdditionDtos;
        }
        for(LCLocationData.OvertimeParkingAddition overtimeParkingAddition : overtimeParkingAdditions){
            parkingAdditionDtos.add(ParkingAdditionDto.parseString(overtimeParkingAddition));
        }
        return parkingAdditionDtos;
    }

    default List<String> getModuleVoltagess(List<LCLocationData.ModuleVoltage> moduleVoltages){
        List<String> moduleVoltagesDtos = Lists.newArrayList();
        if(moduleVoltages == null){
            return moduleVoltagesDtos;
        }
        for(LCLocationData.ModuleVoltage moduleVoltage : moduleVoltages){
            moduleVoltagesDtos.add(ModuleVoltagesDto.parseString(moduleVoltage));
        }
        return moduleVoltagesDtos;
    }

    default List<String> getStaytimeParkingDtos(List<LCLocationData.StaytimeParkingAddition> staytimeParkings){
        List<String> staytimeParkingDtos = Lists.newArrayList();
        if(staytimeParkings == null){
            return staytimeParkingDtos;
        }
        for(LCLocationData.StaytimeParkingAddition staytimeParking : staytimeParkings){
            staytimeParkingDtos.add(StaytimeParkingAdditionDto.parseString(staytimeParking));
        }
        return staytimeParkingDtos;
    }

    default List<String> getSpeedAdditions(List<LCLocationData.SpeedAddition> speedAdditions){
        List<String> speedAdditionDtos = Lists.newArrayList();
        if(speedAdditions == null){
            return speedAdditionDtos;
        }
        for(LCLocationData.SpeedAddition speedAddition : speedAdditions){
            speedAdditionDtos.add(SpeedAdditionDto.parseString(speedAddition));
        }
        return speedAdditionDtos;
    }

    default List<String> getAreaAdditions(List<LCLocationData.AreaAddition> areaAdditions){
        List<String> areaAdditionDtos = Lists.newArrayList();
        if(areaAdditions == null){
            return areaAdditionDtos;
        }
        for(LCLocationData.AreaAddition areaAddition : areaAdditions){
            areaAdditionDtos.add(AreaAdditionDto.parseString(areaAddition));
        }
        return areaAdditionDtos;
    }

    default List<String> getRouteAdditions(List<LCLocationData.RouteAddition> routeAdditions){
        List<String> routeAdditionDtos = Lists.newArrayList();
        if(routeAdditions == null){
            return routeAdditionDtos;
        }
        for(LCLocationData.RouteAddition routeAddition : routeAdditions){
            routeAdditionDtos.add(RouteAdditionDto.parseString(routeAddition));
        }
        return routeAdditionDtos;
    }

    default List<String> getVehicleBreakdowns(List<LCVehicleBreakdown.VehicleBreakdown> vehicleBreakdowns){
        List<String> breakdownAdditionDtos = Lists.newArrayList();
        if(vehicleBreakdowns == null){
            return breakdownAdditionDtos;
        }
        for(LCVehicleBreakdown.VehicleBreakdown vehicleBreakdown : vehicleBreakdowns){
            String data = BreakdownAdditionDto.parseString(vehicleBreakdown);
            if(data == null){
                continue;
            }
            breakdownAdditionDtos.add(data);
        }
        return breakdownAdditionDtos;
    }

    default List<String> getVehicleStatusDataString(List<LCVehicleStatusData.VehicleStatusData> vehicleStatusDatas){
        List<String> vehicleStatusAdditionDtos = Lists.newArrayList();
        if(vehicleStatusDatas == null){
            return vehicleStatusAdditionDtos;
        }
        for(LCVehicleStatusData.VehicleStatusData vehicleStatusData : vehicleStatusDatas){
            vehicleStatusAdditionDtos.add(VehicleStatusAdditionDto.parseString(vehicleStatusData));
        }
        return vehicleStatusAdditionDtos;
    }


    default List<FaultInfoDto> getFaultInfoList(List<LCFaultInfo.FaultListData> faultListData){
        if(faultListData == null){
            return Collections.emptyList();
        }
        List<FaultInfoDto> faultInfoDtos = new ArrayList<>();
        for(LCFaultInfo.FaultListData faultInfo : faultListData){
            faultInfoDtos.add(FaultInfoDto.protoToBean(faultInfo));
        }
        return faultInfoDtos;
    }
}
